#!/bin/bash

# ____  __________  _______  _______      _____  _________________________  ________ 
# \   \/  /\   _  \ \   _  \ \   _  \    /  |  |/   __   \_____  \______  \/   __   \
#  \     / /  /_\  \/  /_\  \/  /_\  \  /   |  |\____    / _(__  <   /    /\____    /
#  /     \ \  \_/   \  \_/   \  \_/   \/    ^   /  /    / /       \ /    /    /    / 
# /___/\  \ \_____  /\_____  /\_____  /\____   |  /____/ /______  //____/    /____/  
#       \_/       \/       \/       \/      |__|                \/                   

#
# This file will install and configure subversion to the machine in question, in
# order for it to work in the IT Tallaght Dublin computer labs
#

LOGLOCATION=/var/log/subversionInstall.log
CONFIGFILE=/etc/subversion/servers

#Check to see if the user has root priviliges.
if [ "$(id -u)" != "0" ]; then
    echo "This script must be run as root, perhaps you meant to sudo?" 1>&2
    echo ""
    echo "  Usage: sudo $0"
    echo ""
    exit 1
fi

echo "--------------------------------------------------------------------------------" >> $LOGLOCATION
date >> $LOGLOCATION

# Install subversion
apt-get install subversion 1>&2 >> /var/log/subversionInstall.log
# Check to see if it worked
if [ $? -gt 0 ]; then
    echo "Subversion installation failed. Please see the log file in /var/log/subversionInstall.log"
    exit 1
fi

# Configure subversion to use the proxy
if [ -x $CONFIGFILE ]; then
    echo "Subversion configuration file is not at $CONFIGFILE , quitting."
    exit 1
else
    echo "http-proxy-host = localhost" >> $CONFIGFILE
    echo "http-proxy-port = 3128" >> $CONFIGFILE
fi

echo "Installation Complete."
echo "Installation log file is located in $LOGLOCATION"


